<?php namespace App\Http\Controllers;

use App\Models\Order as MOrders;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class Orders extends Controller
{
    public function index(Request $request)
    {
        $page = $request->input('page');
        $query = DB::table('orders')->select('*');
        if ($filterId = $request->input('filter.id')) {
            $query->where('orders.id', $filterId);
        }
        if ($filterStatus = $request->input('filter.status')) {
            $query->where('orders.status', $filterStatus);
        }
        return $query->paginate($page['size'], ['*'], 'page', $page['current']);
    }

    //修改订单状态
    public function update(Request $request, $id)
    {
        $order = MOrders::find($id);
        $order->status = $request->input('status');
        $order->save();
        return response('ok', 200);
    }
}
